﻿@model FO.Models.Loan
@{
    ViewBag.Title = "Thêm sản phẩm vay tiêu dùng";
    Layout = "~/Views/Shared/_CpanelLayout.cshtml";
}
<link rel="stylesheet" href="@Url.Content("~/Content/Cpanel/treeview/jquery.treeview.css")" />
<link href="@Url.Content("~/Content/Cpanel/contextmenu/jquery.contextMenu.css")" rel="stylesheet" type="text/css" />

<script src="@Url.Content("~/Content/Cpanel/treeview/jquery.treeview.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/Cpanel/contextmenu/jquery.ui.position.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/Cpanel/contextmenu/jquery.contextMenu.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/js/jquery.fancybox.js")" type="text/javascript"></script>
<script type="text/javascript" src="@Url.Content("~/Content/tinymce/tinymce.min.js")"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(".active-tab").removeClass("active-tab");
        $("a[rel=rel-loan]").parent().parent().css("display", "block");
        $("a[rel=rel-loan]").parent().parent().prev().addClass("active-tab");
        $("a[rel=rel-loan]").addClass("active-tab");
        $(".fancybox-close").click(function () {
            $("#fancy").fadeOut();
        });
        $("#browers-img").click(function () {
            $("#fancy").fadeIn();
            $("#currenttiny").html("browers");
            return false;
        });
    });
    </script>
<script type="text/javascript">
    tinymce.init({
        mode: "exact",
        elements: "description",
        height: "400",
        plugins: [
                "advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
                "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
                "table contextmenu directionality emoticons template textcolor paste fullpage textcolor"
        ],

        toolbar1: "newdocument fullpage | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
        toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor insertimg media code | inserttime preview | forecolor backcolor",
        toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft"
        , setup: function (ed) {
            // Add a custom button
            ed.addButton('insertimg', {
                title: 'Insert Images',
                image: '/content/images/insert-img.png',
                onclick: function () {
                    // Add you own code to execute something on click
                    $("#fancy").fadeIn();
                    $("#currenttiny").html("description");
                    ed.focus();
                    //ed.selection.setContent('Hello world!');
                }
            });
        },
        style_formats: [
              { title: 'Bold text', inline: 'b' },
              { title: 'Red text', inline: 'span', styles: { color: '#ff0000' } },
              { title: 'Red header', block: 'h1', styles: { color: '#ff0000' } },
              { title: 'Example 1', inline: 'span', classes: 'example1' },
              { title: 'Example 2', inline: 'span', classes: 'example2' },
              { title: 'Table styles' },
              { title: 'Table row 1', selector: 'tr', classes: 'tablerow1' }
        ],
        relative_urls: false,
        remove_script_host: false,
        convert_urls: true,
    });
</script>
<script type="text/javascript">
    jQuery.fn.center = function () {
        this.css("position", "absolute");
        this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
                                                $(window).scrollTop()) + "px");
        this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
                                                $(window).scrollLeft()) + "px");
        return this;
    }

    function ajaxdbSelect(sfile) {
        currentSkfile = $(sfile);
        $(".skselected").removeClass("skselected");
        if (!currentSkfile.hasClass("skselected")) {
            currentSkfile.addClass("skselected");
        }
    }
    function ajaxSelect(sfile) {
        //if ($('.mydivclass').length) {
        currentSkfile = $(sfile);
        if (currentSkfile.hasClass("skselected")) {
            currentSkfile.removeClass("skselected");
        }
        else {
            currentSkfile.addClass("skselected");
        }
    }

    function ajaxRfiles(stringpath) {
        $.getJSON("/File/ReadFiles", { folderPath: stringpath }, function (rvdata) {
            htmlcode = "";

            var currentFolder = $(".skselected-folder").attr("rel");
            $("#skFolderContent").html("<center><img src='/Content/loading.gif'></center>");
            $(rvdata).each(function () {
                htmlcode += "<div class='skfile' onclick=\"return ajaxSelect(this)\;\" rel='" + $(this).attr("Name") + "'>";
                htmlcode += "<div class='skfileicon'>";
                if ($(this).attr("isImage")) {
                    htmlcode += "<img src='" + "/" + currentFolder + "/" + $(this).attr("Name") + "'   class='skfileicon-image'/>";
                }
                else {

                }
                htmlcode += "</div>";
                htmlcode += "<div class='skfilename'><p>" + $(this).attr("Name") + "</p></div>";
                htmlcode += "</div>";
            });
            $("#skFolderContent").html(htmlcode);
        });
    }
    function ajaxRtree(mtree) {
        $(".skselected-folder").removeClass("skselected-folder");

        $(mtree).addClass("skselected-folder");
        currentFolder = $(mtree);
        var uploader = new qq.FileUploader({
            element: document.getElementById('file-uploader'),
            multiple: false,
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            params: { FolderPath: currentFolder.attr("rel") },
            multiple: true,
            acceptFiles: "image/*",
            action: '@Url.Action("Upload", "File")',
            onComplete: function (id, fileName, responseJSON) {
                if (uploader.getInProgress() > 0) {
                    return;
                }
                else {
                    $("#refresh-listfile").click();
                }
            }
        });
        var thispath = $(mtree).attr("rel");
        ajaxRfiles(thispath);
        subul = currentFolder.next();
        parentFolder = currentFolder.parent().parent().prev();

        $.getJSON("/File/ReadFolder", { folderPath: thispath }, function (rvdata) {

            subul.addClass("closed");
            subul.html(""); htmlcode = "";
            $(rvdata).each(function () {
                if (parseInt($(this).attr("hasFiles")) > 0 ? "class=closed" : "") {
                    htmlcode += "<li class=closed><span class='folder' onclick=\"return ajaxRtree(this)\;\" rel='" + currentFolder.attr("rel") + "/" + $(this).attr("Name") + "'>";
                    htmlcode += $(this).attr("Name");
                    htmlcode += "</span><ul></ul></li>";
                } else {
                    htmlcode += "<li><span class='folder'  onclick=\"return ajaxRtree(this)\;\" rel='" + currentFolder.attr("rel") + "/" + $(this).attr("Name") + "'>";
                    htmlcode += $(this).attr("Name");
                    htmlcode += "</span></li>";
                }
            });
            subul.html(htmlcode);
        });
    }
    function ajaxReadFolder(foldername) {

        return false;
    }
    $(document).ready(function (e) {

        $(function () {
            $.contextMenu({
                selector: '.skfile',
                callback: function (key, options) {
                    var currentFileName = $(this).attr("rel");
                    var currentFolder = $(".skselected-folder").attr("rel");
                    var currentFile = $(this);
                    var currentPath = currentFolder + "/" + currentFileName;
                    if (key == "edit") {
                        $("#editFile").css("display", "block");
                        $(".edNewFileName").val(currentFileName);
                        $(".edFileName").html(currentFileName);
                    }
                    else if (key == "insert") {

                        var imagepath = $("#AppUrl").html() + "/" + currentFolder + "/" + currentFileName;
                        $("#fancy").fadeOut();
                        if ($("#currenttiny").html() == "browers") {
                            $("#Image").val(currentFileName);
                        }
                        else {
                            tinymce.get($("#currenttiny").html()).selection.setContent("<img src='" + imagepath + "'/>");
                        }

                    }
                    else if (key == 'delete') {
                        //do some thing to delete file.
                        filecount = $(".skselected").length;
                        var msgtext = "tập tin " + currentFileName;

                        if (filecount > 0) {
                            msgtext = filecount + " tập tin đã chọn";
                            if (confirm("Bạn có muốn xóa " + msgtext + " ?")) {
                                $(".skselected").each(function () {
                                    var currentFileSeleted = $(this);
                                    currentFileSeletedFilename = currentFileSeleted.attr("rel");
                                    pathtodelete = currentFolder + "/" + currentFileSeletedFilename;
                                    $.getJSON("/File/ajaxDeleteFile", { spath: pathtodelete }, function (rvdata) {
                                        if (rvdata.status == true) {
                                            currentFileSeleted.remove();
                                        }
                                        else {
                                            alert(rvdata.msg);
                                        }
                                    });
                                });
                            }
                        }
                        else {
                            if (confirm("Bạn có muốn xóa " + msgtext + " ?")) {
                                //do something to deletefile..

                                pathtodelete = currentFolder + "/" + currentFileName;
                                //ajaxDeleteFile
                                $.getJSON("/File/ajaxDeleteFile", { spath: pathtodelete }, function (rvdata) {
                                    if (rvdata.status == true) {
                                        currentFile.remove();
                                    }
                                    else {
                                        alert(rvdata.msg);
                                    }
                                });
                            }
                        }
                    }
                },
                items: {
                    "edit": { name: "Rename", icon: "edit", accesskey: "e" },
                    "insert": { name: "Insert", icon: "add" },
                    "delete": { name: "Delete", icon: "delete" },
                    "sep1": "---------",
                    "quit": { name: "Quit", icon: "quit" }
                }
            });
        });
        $("#editFile").center();
        $("#browser").treeview();
        $("#edSave").click(function () {
            var currentFolder = $(".skselected-folder").attr("rel");
            var path = $(".edFileName").html();
            var newfile = $(".edNewFileName").val();
            $.getJSON("/File/ajaxRenameFile", { spath: currentFolder + "/" + path, foder: currentFolder, newfilename: newfile }, function (rvdata) {
                if (rvdata.status == true) {
                    ajaxRfiles(currentFolder);
                    $("#editFile").css("display", "none");
                }
                else {
                    alert(rvdata.msg);
                }
            });
        });

        $("#can").click(function () { $("#editFile").css("display", "none"); });
        $("#refresh-listfile").click(function () {
            var currentFolder = $(".skselected-folder").attr("rel");
            ajaxRfiles(currentFolder);
            return false;
        });

    });
</script>

<script type="text/javascript">
    tinymce.init({
        mode: "exact",
        elements: "benefit",
        height: "200",
        plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu paste "
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
    });
</script>

<div class="content-module-heading cf">
					
						<h3 class="fl">Thêm sản phẩm vay tiêu dùng</h3>
						<span class="fr expand-collapse-text">Thu nhỏ</span>
						<span class="fr expand-collapse-text initial-expand">Mở rộng</span>
					
					</div> <!-- end content-module-heading -->
					
					
					<div class="innerLR">
 @using (Html.BeginForm())
 {
                
                     <p>
                       @Html.Label("Tên sản phẩm")
                        @Html.TextBoxFor(m => m.LoanName, new { @class = "round default-width-input" })
                         
                       </p>
                <p> @Html.ValidationMessageFor(m => m.LoanName, "", new { @style = "color:red;" })</p>
             <p style="float: left;margin-right: 30px;">   
                        @Html.Label("Ngân hàng")
                           @Html.DropDownListFor(m => m.CompanyID, (IEnumerable<SelectListItem>)ViewBag.CompanyListID)
                             </p>
             <p style="float: left;margin-right: 30px;">   
                        @Html.Label("Loại sản phẩm")
                           @Html.DropDownListFor(m => m.LoanCategoryID, (IEnumerable<SelectListItem>)ViewBag.LoanCateListID)
                             </p>
      <div style="clear:both;"></div>  
             <p>  
                 
                        @Html.Label("Phương án trả lãi")
                           @Html.DropDownListFor(m => m.LoanPlanCategoryID, (IEnumerable<SelectListItem>)ViewBag.LoanPlanListID)
                             </p>
                     <p>
                       @Html.Label("Tiền cho vay thấp nhất")
                        @Html.TextBoxFor(m => m.MinimumBalance, new { @class = "round default-width-input" })
                         
                       </p>
       <p> @Html.ValidationMessageFor(m => m.MinimumBalance, "", new { @style = "color:red;" })</p>
      <p>
                       @Html.Label("Tiền cho vay cao nhất")
                        @Html.TextBoxFor(m => m.MaximumBalance, new { @class = "round default-width-input" })
                         
                       </p>
       <p> @Html.ValidationMessageFor(m => m.MaximumBalance, "", new { @style = "color:red;" })</p>
                         <p>
                       @Html.Label("Lãi suất (% trên năm)")
                        @Html.TextBoxFor(m => m.InterestRate, new { @class = "round default-width-input" })
                         
                       </p>
       <p> @Html.ValidationMessageFor(m => m.InterestRate, "", new { @style = "color:red;" })</p>
                
      <p style="width:100%; float:left; margin-top:30px;">@Html.Label("Quyền lợi")
                        
                        @Html.TextAreaFor(m => m.Benefit, new { id = "benefit" })
                    </p> 
       <p> @Html.ValidationMessageFor(m => m.Benefit, "", new { @style = "color:red;" })</p> 
                     <p style="width:100%; float:left; margin-top:30px;">@Html.Label("Giới thiệu chi tiết")
                        
                        @Html.TextAreaFor(m => m.Description, new { id = "description" })
                    </p>       
                        
       <div style="clear:both;"></div>
                              
                    <input type="submit" value="Thêm mới" class="button round blue image-right ic-add text-upper" />   
                <input type="reset" value="Làm mới" class="button round blue image-right ic-refresh text-upper" />               
 }
                        </div>
<div id="fancy" class="fancybox-overlay fancybox-overlay-fixed" style="width: auto; height: auto; display: none;">
    <div class="fancybox-wrap fancybox-desktop fancybox-type-image fancybox-opened" tabindex="-1" style="width: 1000px; height: auto; position: relative; top: 50px; margin:0 auto; opacity: 1; overflow: visible;">
        <div class="fancybox-skin" style="padding: 15px; width: auto; height: auto;"><div class="fancybox-outer">
            <div class="fancybox-inner" style="overflow: visible; width: 268px; height: auto;">
               <div id="filebrowser">
<div id="currenttiny" style="display:none"></div>


<div id="editFile" style="display:none;">
    <label>FileName:</label> <span class="edFileName"></span><br />
    <label>New File Name:</label><b><input type="text" class="edNewFileName"/></b><span class="edExtention"></span><br />
    <input type="button" id="edSave" value="Save" /><input type="button" id="can" value="Cancel" />
</div>

<div class="content-box" style="width:100%"><!-- Start Content Box -->	
<div id="skyFileManger">
<div id="skFolder">
	<ul id="browser" class="filetree">
		<li><span class="folder" id="rootFolder" rel="Content">Content</span>
			<ul>
               @Html.Action("ReadContentFolder","LayoutHelper")
			</ul>
		</li>
	</ul>
</div>
<div id="skFolderContent"></div>
<div style="clear:both;"></div>
<div class="skupload"><a href="#" style="display:none;" id="refresh-listfile"><img src="@Url.Content("~/Content/loading-icon.gif")" /></a>
<div id="file-uploader" class="ip" style="padding-left: 3px">       
                                        <noscript>          
                                            <p>Please enable JavaScript to use file uploader.</p>
                                            <!-- or put a simple form for upload here -->
                                        </noscript>         
</div>
<div style="clear:both;"></div>
</div>
</div>
</div>


</div>
    </div>
            </div></div><a title="Close" class="fancybox-item fancybox-close" href="javascript:;">

                        </a>

        </div>

    </div>